package com.audaque.springboot.foshanupload.mongodb.config;

import com.audaque.springboot.foshanupload.mongodb.properties.MongodbProperties;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoDatabase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class MongoDatabaseConfig {

    @Autowired
    private MongodbProperties mongodbProperties;
    @Autowired
    private MongoClient mongoClient;
    /**
     * 官方依赖的客户端
     * 单节点 mongodb 不支持事务，需要搭建 MongoDB 复制集。
     */
    @Bean
    MongoDatabase mongoDatabase() {
        // 连接到数据库,没有则创建
         return mongoClient.getDatabase(mongodbProperties.getDb());
    }

}
